<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="用户" prop="userName">
				<el-input v-model="queryParams.userName" placeholder="请输入用户" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="项目名" prop="itemName">
				<el-input v-model="queryParams.itemName" placeholder="请输入项目名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-table v-loading="loading" :data="technicianRadarItemOrderList">
			<el-table-column label="ID" align="center" prop="id" />
			<el-table-column label="用户" align="center" prop="userName" />
			<el-table-column label="技师" align="center" prop="tname" />
			<el-table-column label="项目名" align="center" prop="itemName" />
			<el-table-column label="项目图" align="center" prop="itemPicture">
				<template slot-scope="scope">
					<image-preview :src="scope.row.itemPicture" :width="50" :height="50" />
				</template>
			</el-table-column>
			<el-table-column label="项目时长" align="center" prop="itemTime">
				<template slot-scope="scope">
					<span>{{scope.row.itemTime}}分钟</span>
				</template>
			</el-table-column>
			<el-table-column label="所在地区" align="center" prop="serviceAddress" />
			<el-table-column label="下单时间" align="center" prop="placeOrderTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.placeOrderTime) }}</span>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />

		<!-- 添加或修改订单雷达统计对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listTechnicianRadarItemOrder,
		getTechnicianRadarItemOrder,
		delTechnicianRadarItemOrder,
		addTechnicianRadarItemOrder,
		updateTechnicianRadarItemOrder
	} from "@/api/technicianRadarItemOrder/technicianRadarItemOrder";

	export default {
		name: "TechnicianRadarItemOrder",
		dicts: ['is_use_coupon', 'pay_type', 'order_status', 'order_type', 'is_exception', 'is_open_vip'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 订单雷达统计表格数据
				technicianRadarItemOrderList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 创建时间时间范围
				daterangePlaceOrderTime: [],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					userName: null,
					tid: null,
					itemName: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询订单雷达统计列表 */
			getList() {
				this.loading = true;
				this.queryParams.params = {};
				if (null != this.daterangePlaceOrderTime && '' != this.daterangePlaceOrderTime) {
					this.queryParams.params["beginPlaceOrderTime"] = this.daterangePlaceOrderTime[0];
					this.queryParams.params["endPlaceOrderTime"] = this.daterangePlaceOrderTime[1];
				}
				listTechnicianRadarItemOrder(this.queryParams).then(response => {
					this.technicianRadarItemOrderList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					partnerOrderNo: null,
					orderNo: null,
					transactionId: null,
					userId: null,
					tid: null,
					itemId: null,
					itemSpecsId: null,
					itemName: null,
					itemPicture: null,
					itemTime: null,
					addressId: null,
					addressUserName: null,
					addressTel: null,
					addressDetail: null,
					serviceTime: null,
					orderRemark: null,
					needPayPrice: null,
					orderTotalPrice: null,
					modeTravel: null,
					orderItemPrice: null,
					orderFarePrice: null,
					discountPrice: null,
					isUserCoupon: null,
					userCouponId: null,
					payType: null,
					placeOrderTime: null,
					payTime: null,
					orderNum: null,
					orderType: null,
					orderStatus: null,
					isOpenMembership: null,
					openMemberId: null,
					openMemberPrice: null,
					distance: null,
					takeOrderWaitTime: null,
					startServiceWaitTime: null,
					serviceTotalTime: null,
					leaveAddress: null,
					takeOrderTime: null,
					proceedTime: null,
					arriveAddress: null,
					arrivePicture: null,
					arriveRemark: null,
					arriveTime: null,
					startServiceTime: null,
					stopServiceTime: null,
					realServiceTime: null,
					cancelTime: null,
					cancelReason: null,
					cancelDescribe: null,
					expectIncome: null,
					isException: null,
					isDelete: null,
					updateTime: null,
					createTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.daterangePlaceOrderTime = [];
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加订单雷达统计";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				getTechnicianRadarItemOrder(id).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改订单雷达统计";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.id != null) {
							updateTechnicianRadarItemOrder(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addTechnicianRadarItemOrder(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$modal.confirm('是否确认删除订单雷达统计编号为"' + ids + '"的数据项？').then(function() {
					return delTechnicianRadarItemOrder(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('technicianRadarItemOrder/technicianRadarItemOrder/export', {
					...this.queryParams
				}, `technicianRadarItemOrder_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>